import requests
import re

from Constances import UserAgent

# 提取豆瓣电影排行榜top250
url = "https://movie.douban.com/top250"
header = {
    "User-Agent": UserAgent
}
resp = requests.get(url, headers=header)
# print(resp.text)
pageContent = resp.text

rule = re.compile(r'<li>.*?<div class="item">.*?<span class="title">(?P<name>.*?)'
                  r'</span>.*?<p class="">.*?<br>(?P<year>.*?)&nbsp.*?'
                  r'</p>.*?<span class="rating_num" property="v:average">(?P<score>.*?)'
                  r'</span>.*?<span>(?P<people>.*?)</span>', re.S)
it = rule.finditer(pageContent)
for item in it:
    # print(item.group())
    print(item.group("name"), item.group("year").strip(), item.group("score"), item.group("people"))